package com.zelin.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.zelin.dao.SpecificationOptionDao;
import com.zelin.entity.SpecificationOptionEntity;
import com.zelin.entity.vo.SpecificationVoEntity;
import com.zelin.sellergoods.service.SpecificationOptionService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.Query;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service
public class SpecificationOptionServiceImpl extends ServiceImpl<SpecificationOptionDao, SpecificationOptionEntity> implements SpecificationOptionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpecificationOptionEntity> page = this.page(
                new Query<SpecificationOptionEntity>().getPage(params),
                new QueryWrapper<SpecificationOptionEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 功能: 根据规格找到规格及其规格选项列表
     * 参数:
     * 返回值: java.util.List<SpecificationVoEntity>
     * 时间: 2021/7/28 15:42
     */
    @Override
    public List<SpecificationVoEntity> findSpecList(List<SpecificationVoEntity> specs) {
        for (SpecificationVoEntity spec : specs) {
            Long id = spec.getId();
            List<SpecificationOptionEntity> options = this.list(new QueryWrapper<SpecificationOptionEntity>().eq("spec_id", id));
            spec.setOptions(options);
        }
        return specs;
    }

}